package com.apache.website.service.plugins;

import java.util.List;
import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.database.constant.Validator;
import com.apache.database.model.Page;
import com.apache.tools.ClassToolsUtil;
import com.apache.website.entity.Channel;
import com.apache.website.manager.ChannelManager;

public class ChannelListPluginImpl implements PluginConnector {

	private ChannelManager channelManager;

	public Object execute(ParamsVo param) throws Exception {
		ResultEntity entity = new ResultEntity();
		ParamsVo<Channel> cvo = new ParamsVo<Channel>();
		Channel channel = new Channel();
		channel = (Channel) ClassToolsUtil.getInstance().convert2Bean(param.getParams(), channel);
		cvo.setObj(channel);
		int pageSize = Integer.valueOf(Validator.getDefaultStr(String.valueOf(param.getParams("pageSize")), "0"));
		int pageIndex = Integer.valueOf(Validator.getDefaultStr(String.valueOf(param.getParams("pageIndex")), "0"));
		if (pageSize == 0 && pageIndex == 0) {
			List<Channel> list = channelManager.getList(cvo);
			entity.setEntity(list);
		} else {
			cvo.setParams("pageIndex", pageIndex);
			cvo.setParams("pageSize", pageSize);
			Page page = channelManager.getPageInfo(cvo);
			entity.setEntity(page);
		}
		entity.setResult("true");
		entity.setMessage("查询成功");
		return entity;
	}

	public void setChannelManager(ChannelManager channelManager) {
		this.channelManager = channelManager;
	}

}
